package com.yanxp.launcher;

import com.yanxp.App;
import org.apache.catalina.LifecycleException;
import org.apache.catalina.startup.Tomcat;

import javax.servlet.ServletException;

/**
 * @author yuanxp
 * @Date 2021/4/15 9:09
 */
public class SpringApplication {


    public static void run(Class clazz,Object...args) throws LifecycleException, ServletException {
        final Tomcat tomcat = new Tomcat();
        tomcat.addWebapp("/","D:\\");
        tomcat.start();
        //守护线程
        Thread awaitThread = new Thread("container") {

            @Override
            public void run() {
                tomcat.getServer().await();
            }

        };

        awaitThread.setContextClassLoader(clazz.getClassLoader());
        awaitThread.setDaemon(false);
        awaitThread.start();
    }

}
